################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis Tax and Benefit System
# Figure B 5
#
#Verena Fetscher
#July 2022
####################



####################
# Load data
####################
load("Benefits.Rda")




#Combine benefit concentration indicator for each family type in one plot
#Order by mean replacement rate
(df %>%
   group_by(cntry) %>% 
   filter(time=="Mean") %>%
   summarize(mean = mean(allRepl)) %>%
   arrange(+mean))$cntry -> order


#Produces A.2 in Appendix
ggplot(df,aes(allRepl,cntry,color = as.factor(time)))+ 
  geom_point(size=4,aes(shape=as.factor(time)))+
  scale_color_manual(values=c("lightgray","black","darkgray"),
                     name="Family type")+
  scale_shape_manual(values=c(16,8,16),name="Family type")+
  scale_y_discrete(limits = order)+
  ylab("Country") + xlab("Benefit concentration indicator") +
  theme_bw()+
  theme(panel.border=element_blank(),
        axis.line=element_line(),
        legend.position="bottom",
        legend.text = element_text(size = 14),
        legend.title = element_text(size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=14))


##########################
#Save figure
##########################

ggsave(file="figure_b5.pdf", height = 5.83, width = 8.27, units = "in")

